layui.use(['form','layer'],function(){
    var form = layui.form
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery;
    form.on("submit(btnSubmit)",function(data){
        //弹出loading
        var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});

        var field = data.field;
        var isAuto = field.isAuto;
        if(isAuto == undefined){
            isAuto="2";
        }
        var status = field.status;
        if (status == undefined || status == "undefined") {
            status="1";
        }
        var totalNum = field.totalNum;
        var periodsNum = $("#periodsNum").val();
        // 实际使用时的提交信息
        $.post("/activity/updateOrAddEntity",{
            id : $("#id").val(),
            itemId : $("#itemId").val(),
            totalNum : totalNum,
            periodsNum : periodsNum,
            title : "第"+periodsNum+"期",
            isAuto : isAuto,
            status : status
        },function(result){
            if(1==result.returnInfo.state){
                top.layer.close(index);
                top.layer.msg("操作成功！");
                layer.closeAll("iframe");
                //刷新父页面
                parent.location.reload();
            }else{
                top.layer.msg(result.returnInfo.errorMsg);
            }
        },"json")
        return false;
    });
})